import axios from "axios";
import store from "@/store";
const request = axios.create({
  baseURL: "https://lianghj.top:8888/api/",
  // baseURL: "http://weldon.net.cn:8889/api",
  timeout: 5000,
});
request.interceptors.request.use(
  (config) => {
    const token = store.state.user.token;
    if (token) {
      config.headers.Authorization = token;
    }
    return config;
  },
  (err) => {
    return Promise.reject(err);
  }
);
request.interceptors.response.use(
  (response) => {
    return response.data;
  },
  (err) => {
    // if (err.response.status === 401) {
    //   store.commit("user/delToken");
    //   router.push("/login");
    //   Message.error("登录过期，请重新登录");
    // } else {
    //   Message.error(err?.response?.data?.message || "登录出错，重新登录");
    //   router.push("/login");
    // }
    return Promise.reject(err);
  }
);
export default request;
